slog-try
Convenience macros for logging with an optional slog Logger.
Required dependencies
Add slog
and slog-try
as a dependency in your Cargo.toml file.
[]
= "^2"
= "^0.2"
Project setup
Add the new dependencies as external crates into the main.rs
or lib.rs
file of your project:
extern crate slog;
extern crate slog_try;
Usage example
Consider HasOptLogger
, a data strcuture with an optionally attachable logger:
The macros contained in slog-try
encapsulate the required boilerplate to use this logger without verifying whether the optional field actually contains a logger or not:
let mut opt_logger= HasOptLogger ;
// Try to log even if no logger exist
try_info!;
try_info!;
// Setup a `Logger`
let plain = new;
let logger = root;
opt_logger.logger = Some;
// Call again with the new attached logger
try_info!;
try_info!;